package com.yami.shop.api.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.bean.app.dto.CarListDto;
import com.yami.shop.bean.app.dto.MyOrderDto;
import com.yami.shop.bean.app.dto.SearchCarDto;
import com.yami.shop.bean.app.param.CarListParam;
import com.yami.shop.bean.app.param.CarSubmitParam;
import com.yami.shop.bean.app.param.EditLicensePlateNumberParam;
import com.yami.shop.bean.app.param.ManagementSubmitParam;
import com.yami.shop.common.response.ServerResponseEntity;
import com.yami.shop.common.util.PageParam;
import com.yami.shop.security.api.util.SecurityUtils;
import com.yami.shop.service.CarManagementService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Parameters;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.checkerframework.checker.units.qual.C;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * CarManagementController
 *
 * @Author Administrator
 * @Date 2025/4/10 16:43
 */
@RestController
@RequestMapping("/p/carManagement")
public class CarManagementController {

    @Resource
    private CarManagementService carManagementService;

    /**
     * 车辆列表
     */
    @GetMapping("/list")
    public ServerResponseEntity<IPage<CarListDto>> list(@RequestParam(value = "ridgepole") String ridgepole, @RequestParam(value = "roomNumber") String roomNumber, PageParam<CarListDto> page) {
        IPage<CarListDto> myOrderDtoIpage = carManagementService.carList(page, ridgepole, roomNumber);
        return ServerResponseEntity.success(myOrderDtoIpage);
    }

    @GetMapping("/myList")
    public ServerResponseEntity<List<CarListDto>> myList() {
        Integer userId = SecurityUtils.getUser().getUserId();
        List<CarListDto> myOrderDtoIpage = carManagementService.myCarList(userId);
        return ServerResponseEntity.success(myOrderDtoIpage);
    }

    @PostMapping("/submit")
    public ServerResponseEntity<Void> submit(@Validated @RequestBody CarSubmitParam carSubmitParam) {
        Integer userId = SecurityUtils.getUser().getUserId();
        carSubmitParam.setUserId(userId);
        carManagementService.submit(carSubmitParam);
        return ServerResponseEntity.success();
    }

    @GetMapping("/search")
    public ServerResponseEntity<SearchCarDto> search(@RequestParam(value = "licensePlateNumber") String licensePlateNumber) {
        SearchCarDto searchCarDto = carManagementService.search(licensePlateNumber);
        return ServerResponseEntity.success(searchCarDto);
    }

    @PostMapping("/managementSubmit")
    public ServerResponseEntity<Void> managementSubmit(@Validated @RequestBody ManagementSubmitParam param) {
        Integer userId = SecurityUtils.getUser().getUserId();
        carManagementService.managementSubmit(param,userId);
        return ServerResponseEntity.success();
    }

    @PostMapping("/editLicensePlateNumber")
    public ServerResponseEntity<Void> editLicensePlateNumber(@Validated @RequestBody EditLicensePlateNumberParam param) {
        Integer userId = SecurityUtils.getUser().getUserId();
        param.setUserId(userId);
        carManagementService.editLicensePlateNumber(param);
        return ServerResponseEntity.success();
    }
}
